//
//  HMMainViewController.m
//  HowToDo
//
//  Created by Apple on 16/12/31.
//  Copyright © 2016年 KY. All rights reserved.
//

#import "HMMainViewController.h"
#import "HMHomeTableViewController.h"
#import "HMSubscribeTableViewController.h"
#import "HMListenViewController.h"
#import "HMBuyTableViewController.h"
#import "HMMeTableViewController.h"
#import "HMBaseNavController.h"
//  根视图控制器
@interface HMMainViewController ()

@end

@implementation HMMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addViewControllers];
    self.tabBar.shadowImage = [UIImage imageNamed:@"tabbar_shadow_iphone6_plus"];
    [self.tabBar setTintColor:[UIColor orangeColor]];
}


-(void)addViewControllers
{
    UIViewController* home = [self creatControllersWithTitle:@"首页" ImageName:@"tabbar_index_select_1_30x30_" ClassName:@"HMHomeTableViewController"];
    UIViewController* order = [self creatControllersWithTitle:@"订阅" ImageName:@"tabbar_index_select_2_30x30_" ClassName:@"HMSubscribeTableViewController"];
    
    UIViewController* learnNow = [self creatControllersWithTitle:@"马上学习" ImageName:@"tabbar_index_select_3_90x60_" ClassName:@"HMListenViewController"];
    
    UIViewController* bought = [self creatControllersWithTitle:@"易购" ImageName:@"tabbar_index_select_4_30x30_" ClassName:@"HMBuyTableViewController"];
    
    UIViewController* profile = [self creatControllersWithTitle:@"我的" ImageName:@"tabbar_index_select_5_30x30_" ClassName:@"HMMeTableViewController"];
    
    self.viewControllers = @[home,order,learnNow,bought,profile];
}



-(UIViewController*)creatControllersWithTitle:(NSString*)title ImageName:(NSString*)selectedImageName ClassName:(NSString*)className
{
    Class class = NSClassFromString(className);
    
    UIViewController* viewContrller = [[class alloc]init];
    viewContrller.title = title;
    //设置图片
    NSString* norImgName = [selectedImageName stringByReplacingOccurrencesOfString:@"_select" withString:@""];
    
    viewContrller.tabBarItem.image = [[UIImage imageNamed:norImgName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    viewContrller.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置字体颜色
    
    HMBaseNavController* nav = [[HMBaseNavController alloc]initWithRootViewController:viewContrller];
    
    return nav;
}

@end
